// 
//  DotNetNuke? - http://www.dotnetnuke.com
//  Copyright (c) 2002-2006
//  by DotNetNuke Corporation
// 
//  Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated 
//  documentation files (the "Software"), to deal in the Software without restriction, including without limitation 
//  the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and 
//  to permit persons to whom the Software is furnished to do so, subject to the following conditions:
// 
//  The above copyright notice and this permission notice shall be included in all copies or substantial portions 
//  of the Software.
// 
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED 
//  TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 
//  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF 
//  CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
//  DEALINGS IN THE SOFTWARE.
// 

using System;
using DotNetNuke;
using DotNetNuke.Security.Roles;
using DotNetNuke.Security.Membership;
using System.Web.Compilation;
using System.Data;
using System.Reflection;
using System.Collections.Generic;
using System.Web.UI.WebControls;
using DotNetNuke.Services.Exceptions;
using DotNetNuke.Common;

namespace DotNetNuke.Modules.IWebCSharp
{
    partial class IWeb_Edit : DotNetNuke.Entities.Modules.PortalModuleBase
    {

        protected void Page_Load(System.Object sender, System.EventArgs e)
        {
            try
            {
                if (!UserInfo.IsSuperUser)
                {
                    GVWebMethodSecurity.Visible = false;
                    Response.Redirect(Globals.NavigateURL());
                }
                else
                {

                    List<IWEBMethodInfo> IWEBMethodInfoList;
                    IWEBMethodInfoList = IWEBMethods.GetMethodsInDatabase();

                    if (IWEBMethodInfoList.Count == 0)
                    {
                        IWEBMethods objIWEBMethods = new IWEBMethods();
                        objIWEBMethods.AddandDeleteMethods();
                    }

                    if (!(Page.IsPostBack))
                    {

                        if (!(IWebController.GetIWebSettings(PortalId, "SecurityKey") == null))
                        {
                            this.txtSecurityKey.Text = IWebController.GetIWebSettings(PortalId, "SecurityKey").ToString();
                        }
                        else
                        {
                            this.txtSecurityKey.Text = "";
                        }

                    }
                }

            }
            catch (Exception exc)
            { // Module failed to load
                Exceptions.ProcessModuleLoadException(this, exc);
            }
        }

        protected void cmdBack_Click(object sender, System.EventArgs e)
        {
            Response.Redirect(Globals.NavigateURL());
        }


        protected void btnUpdateSettings_Click(object sender, System.EventArgs e)
        {
            IWebInfo IWebInfo = new IWebInfo();

            IWebInfo.PortalID = PortalId;
            IWebInfo.SettingID = "SecurityKey";
            IWebInfo.Setting = this.txtSecurityKey.Text;

            if (IWebController.CheckIWebSettings(PortalId, "SecurityKey") > 0)
            {
                IWebController.UpdateIWebSettings(IWebInfo);
            }
            else
            {
                IWebController.InsertIWebSettings(IWebInfo);
            }

        }


        protected void lnkRefresh_Click(object sender, System.EventArgs e)
        {
            IWEBMethods objIWEBMethods = new IWEBMethods();
            objIWEBMethods.AddandDeleteMethods();
            this.GVWebMethodSecurity.DataBind();
        }


        protected void ddlPortalList_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            this.GVWebMethodSecurity.DataBind();
        }


        protected void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            int intPortalID;
            string strMethodName;
            string strSecuritySetting;

            DropDownList objDropDownList;
            objDropDownList = ((DropDownList)(sender));

            intPortalID = Convert.ToInt32(this.ddlPortalList.SelectedValue);
            strMethodName = objDropDownList.ValidationGroup.ToString();
            strSecuritySetting = objDropDownList.SelectedItem.ToString();

            IWEBMethods.UpdateSecuritySetting(intPortalID, strMethodName, strSecuritySetting);

        }


        protected void lnkSponsors_Click(object sender, System.EventArgs e)
        {
            DotNetNuke.Entities.Modules.ModuleController objModules = new DotNetNuke.Entities.Modules.ModuleController();
            Response.Redirect(DotNetNuke.Common.Globals.NavigateURL(PortalSettings.ActiveTab.TabID, "sponsors", "mid=" + (Convert.ToString(ModuleId))));
        }


    }

}

